package consulTest.controller;

import consulTest.Entity.TestEntity;
import consulTest.service.TestEntityService;
import consulTest.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lipor
 * Date 2020/9/8
 */
@RestController
public class TestEntityController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private TestEntityService testEntityService;


    @GetMapping("/get/{id}")
    public TestEntity test02(@PathVariable("id") Integer id) {
        TestEntity testEntity;
        testEntity = testEntityService.findById(id);
        return testEntity;

    }

    @GetMapping("/put/{id}")
    public TestEntity test01(@PathVariable("id") Integer id) {
        TestEntity testEntity;
        testEntity = testEntityService.findByIdPut(id);
        return testEntity;
    }

    @GetMapping("setRedis")
    public void test03() {
        redisUtil.set("lipor", "lipor");
    }

    @GetMapping("clear")
    public String test04() {
        return testEntityService.clear();
    }

    @GetMapping("entity")
    public String test05(TestEntity testEntity) {
        testEntity.setName("9");
        testEntity.setAge(9);
        testEntityService.addEntity(testEntity);
        TestEntity byId = testEntityService.findById(testEntity.getId());
        return testEntity.getId().toString();
    }

}
